﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using System.Threading.Tasks;

namespace ebMS3dotnet.Core
{
    public static class ChannelFactoryOperations
    {
        public static TChannel CreateChannelForUserMessage<TChannel>(this ChannelFactory<TChannel> channelFactory,
            UserMessageInfo userMessageInfo)
        {
            TChannel channel = channelFactory.CreateChannel();

            ebMS3ClientParameters clientParameters = new ebMS3ClientParameters()
            {
                UserMessage = userMessageInfo
            };

            ((IChannel)(object)channel).GetProperty<ChannelParameterCollection>().Add(clientParameters);
            return channel;
        }
    }
}
